/*
 * Copyright © 2024-2025 Wenze Wei
 *
 * This file is part of StadionOS.
 *
 * This Source Code Form is subject to the terms of the GNU General Public License, v. 2.0.
 * You can obtain a copy of the GPL at
 * https://www.gnu.org/licenses/old-licenses/gpl-2.0.html.
 *
 * Software distributed under the License is distributed on an "AS IS" basis,
 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for
 * the specific language governing rights and limitations under the License.
 */

#ifndef LIBS_MALLOC_H
#define LIBS_MALLOC_H

#include <stdlib.h>
#include <stdio.h>
#include <errno.h>  
#include <pthread.h>
#include "./string.h"
#include "./errorr.h"

#define ALIGNMENT 16



typedef struct Block {  
    size_t size;
    struct Block *next;
    int free;
} TBlock;

static TBlock *head = NULL;
static size_t total_allocated = 0;
static pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER;

size_t ALIGN(size_t size);
void   Sinit_memory_pool(size_t total_size);
void   Scleanup_memory_pool();
void   Scleanup_memory_pool();

void  *Smalloc(size_t size);
void   Sfree(void *ptr);
void  *Scalloc(size_t num, size_t size);
void  *Srealloc(void *ptr, size_t new_size);
int    Serror();

void  *Smemcpy(void *dest, const void *src, size_t n);
void  *Smemmove(void *dest, const void *src, size_t n);
int    Smemcmp(const void *str1, const void *str2, size_t n);
void  *Smemset(void *s, int c, size_t n);
void  *Smemchr(const void *s, int c, size_t n);


#endif //LIBS_MALLOC_H
